/** 
 * Copyright (c) 2024, Qi Yaolong.
 * dragon@hbu.edu.cn
 * HeBei University, China.
 * 
 * 简体中文
 * 保留所有权利。除非符合（遵守）以下条款，否则您不得使用此文件：
 * 
 * 禁止任何未经授权的个人或组织以任何形式将本程序及其附属资料、创新、创意、架构设计、算法、衍生作品
 * 等用于任何商业目的、盈利活动、各类竞赛(比赛)、直播教学、录播教学、线下课程、书籍编写、教材编写、
 * 会议、培训、公益活动、项目课题、毕业设计、毕业论文、学术论文等。
 * 
 * 本程序由版权持有人和贡献人“按原样”提供，不提供任何明示或暗示担保，包括但不局限于对适销性和特定
 * 用途适合性的暗示担保。在任何情况下，版权持有人或贡献人对因使用本程序而导致的任何直接、间接、附带、
 * 特殊、典型或后果性损害（包括但不限于购买替代商品或服务；使用损失、数据丢失或利润损失；业务中断）
 * 不承担任何责任，无论其如何产生，也不论其责任理论为何，无论是合同、严格责任还是侵权（包括疏忽或
 * 其他），即使已告知此类损害的可能性。
 * 
 * English
 * All rights reserved. You may NOT use this file except in compliance with the
 * following terms:
 * 
 * IT IS PROHIBITED FOR ANY UNAUTHORIZED PERSON OR ENTITY TO USE THIS PROGRAM AND 
 * ITS ANCILLARY DATA, INNOVATIONS, CONCEPTS, ARCHITECTURE DESIGN, ALGORITHMS, 
 * DERIVED WORKS, ETC., IN ANY FORM FOR COMMERCIAL PURPOSES, PROFIT-MAKING 
 * ACTIVITIES, VARIOUS COMPETITIONS (CONTESTS), LIVE TEACHING, PRE-RECORDED 
 * LESSONS, OFFLINE COURSES, BOOK WRITING, CONFERENCES, TRAININGS, PUBLIC WELFARE 
 * ACTIVITIES, PROJECTS, TOPICS, GRADUATION DESIGNS, DISSERTATIONS, THESES, AND 
 * OTHER APPLICATIONS.
 * 
 * THIS PROGRAM IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS PROGRAM, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#include <stdio.h>
#include <unistd.h>
#include "ohos_init.h"
#include "cmsis_os2.h"
#include "iot_gpio.h"
#include "../inc/iot_gpio_ex.h"
#include "../inc/oled_ssd1306.h"

uint8_t fonts1[][32] = {
    {0x04, 0x04, 0x04, 0x04, 0x04, 0xFC, 0x44, 0x44, 0x44, 0x44, 0x44, 0xC4, 0x04, 0x04, 0x04, 0x00, 0x80, 0x40, 0x20, 0x18, 0x06, 0x01, 0x00, 0x00, 0x40, 0x80, 0x40, 0x3F, 0x00, 0x00, 0x00, 0x00},
    {0x40, 0x3C, 0x10, 0xFF, 0x10, 0x10, 0x20, 0x10, 0x8F, 0x78, 0x08, 0xF8, 0x08, 0xF8, 0x00, 0x00, 0x02, 0x06, 0x02, 0xFF, 0x01, 0x01, 0x04, 0x42, 0x21, 0x18, 0x46, 0x81, 0x40, 0x3F, 0x00, 0x00},
    {0x00, 0x02, 0x02, 0x02, 0xE2, 0x3E, 0x22, 0x22, 0x22, 0x22, 0x22, 0xE2, 0x02, 0x02, 0x00, 0x00, 0x40, 0x40, 0x40, 0x47, 0x44, 0x44, 0x44, 0x44, 0x44, 0x74, 0x4E, 0x41, 0x40, 0x40, 0x40, 0x00},
    {0x02, 0xFE, 0x92, 0x92, 0xFE, 0x02, 0x00, 0x10, 0x11, 0x16, 0xF0, 0x14, 0x13, 0x10, 0x00, 0x00, 0x10, 0x1F, 0x08, 0x08, 0xFF, 0x04, 0x81, 0x41, 0x31, 0x0D, 0x03, 0x0D, 0x31, 0x41, 0x81, 0x00},
};

uint8_t fonts2[] = {
    0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0xFC, 0x44, 0x44, 0x44, 0x44, 0xE4, 0x44, 0x06, 0x04, 0x00,
    0x00, 0x80, 0x40, 0x20, 0x10, 0x0E, 0x01, 0x00, 0x40, 0x80, 0x40, 0x3F, 0x00, 0x00, 0x00, 0x00,
    0x40, 0x3C, 0x10, 0xFF, 0x90, 0xA0, 0x10, 0x1F, 0xF0, 0x10, 0xF0, 0x10, 0x10, 0xF8, 0x10, 0x00,
    0x02, 0x02, 0x01, 0xFF, 0x00, 0x10, 0x0C, 0x43, 0x30, 0x0E, 0x41, 0x80, 0x40, 0x3F, 0x00, 0x00,
    0x00, 0x02, 0x02, 0x02, 0xFE, 0x12, 0x12, 0x12, 0x12, 0x12, 0xFA, 0x12, 0x03, 0x02, 0x00, 0x00,
    0x40, 0x40, 0x40, 0x46, 0x45, 0x44, 0x44, 0x44, 0x44, 0x44, 0x7F, 0x40, 0x40, 0x60, 0x40, 0x00,
    0x02, 0x02, 0xFE, 0x12, 0x12, 0xFE, 0x02, 0x11, 0x12, 0x16, 0xF0, 0x14, 0x12, 0x93, 0x00, 0x00,
    0x20, 0x20, 0x3F, 0x11, 0x11, 0xFF, 0x91, 0x41, 0x21, 0x19, 0x07, 0x19, 0x61, 0xC1, 0x41, 0x00,
    0x00, 0xF8, 0x48, 0x48, 0x48, 0x48, 0xFF, 0x48, 0x48, 0x48, 0x48, 0xFC, 0x08, 0x00, 0x00, 0x00,
    0x00, 0x07, 0x02, 0x02, 0x02, 0x02, 0x3F, 0x42, 0x42, 0x42, 0x42, 0x47, 0x40, 0x70, 0x00, 0x00,
    0x00, 0x00, 0xFE, 0x02, 0x82, 0x82, 0x82, 0x82, 0xFE, 0x82, 0x82, 0x82, 0xC3, 0x82, 0x00, 0x00,
    0x40, 0x30, 0x0F, 0x40, 0x40, 0x40, 0x40, 0x40, 0x7F, 0x40, 0x42, 0x44, 0x4C, 0x60, 0x40, 0x00,
    0x20,0x30,0xac,0x63,0x30,0x48,0x48,0x48,0x48,0xff,0x48,0x48,0x68,0x4c,0x08,0x00,
    0x22,0x63,0x22,0x12,0x12,0x12,0x02,0x02,0x02,0xff,0x02,0x12,0x22,0x1f,0x02,0x00,
    0x00,0x00,0xfc,0x24,0x24,0x24,0xfc,0xa5,0xa6,0xa4,0xfc,0x24,0x34,0x26,0x04,0x00,
    0x40,0x20,0x9f,0x80,0x42,0x42,0x26,0x2a,0x12,0x2a,0x26,0x42,0x40,0xc0,0x40,0x00,
    0x20,0x30,0xac,0x63,0x30,0x48,0x48,0x48,0x48,0xff,0x48,0x48,0x68,0x4c,0x08,0x00,
    0x22,0x63,0x22,0x12,0x12,0x12,0x02,0x02,0x02,0xff,0x02,0x12,0x22,0x1f,0x02,0x00,
    0x20,0x22,0xec,0x00,0x20,0x22,0xaa,0xaa,0xaa,0xbf,0xaa,0xaa,0xeb,0xa2,0x20,0x00,
    0x00,0x00,0x7f,0x20,0x10,0x00,0xff,0x0a,0x0a,0x0a,0x4a,0x8a,0x7f,0x00,0x00,0x00,
    0x24,0x24,0xa4,0xfe,0xa3,0x22,0x10,0x88,0x8c,0x57,0xe4,0x24,0x14,0x0c,0x00,0x00,
    0x04,0x02,0x01,0xff,0x00,0x83,0x80,0x88,0x44,0x46,0x29,0x31,0x11,0x0d,0x03,0x00,
    0x40,0x40,0x40,0x40,0x7e,0x40,0x40,0xff,0x48,0x48,0x48,0x4c,0x48,0x60,0x40,0x00,
    0x00,0x80,0x88,0x84,0x43,0x42,0x20,0x2f,0x10,0x10,0x0c,0x03,0x02,0x00,0x00,0x00,
    0x00,0x02,0x42,0x62,0x52,0x4a,0x46,0xc2,0x42,0x42,0x52,0x62,0xc3,0x02,0x00,0x00,
    0x40,0x40,0x44,0x44,0x44,0x44,0x44,0x7f,0x44,0x44,0x44,0x46,0x44,0x60,0x40,0x00,
    0x80,0x82,0x82,0x82,0xfe,0x82,0x82,0x82,0x82,0x82,0xfe,0x82,0x83,0xc2,0x80,0x00,
    0x00,0x80,0x40,0x30,0x0f,0x00,0x00,0x00,0x00,0x00,0xff,0x00,0x00,0x00,0x00,0x00,
    0x00,0xfc,0x40,0x89,0x12,0x86,0x90,0x92,0xf2,0x8a,0xca,0x82,0x02,0xff,0x02,0x00,
    0x00,0xff,0x08,0x7c,0x02,0x00,0x7c,0x24,0x27,0x24,0x3e,0x44,0x80,0x7f,0x00,0x00,
    0x40,0x40,0xfe,0x40,0x40,0x80,0xfc,0x40,0x40,0xff,0x20,0x20,0xf0,0x20,0x00,0x00,
    0x20,0x60,0x3f,0x10,0x10,0x00,0x3f,0x40,0x40,0x5f,0x44,0x48,0x47,0x40,0x70,0x00,
    0x80,0x64,0x24,0x24,0x3f,0x24,0x24,0xff,0x24,0x24,0x3f,0x24,0x26,0xa4,0x60,0x00,
    0x00,0x00,0x00,0x7f,0x01,0x01,0x01,0xff,0x01,0x21,0x41,0x3f,0x00,0x00,0x00,0x00,
};

/**
 * @brief Display Chinese characters on the OLED screen.
 *
 * This function displays Chinese characters from fonts1 on the OLED screen at the specified position.
 *
 * @param x The x-coordinate of the position.
 * @param y The y-coordinate of the position.
 * @param idx The index of the character in fonts1.
 */
void OledShowChinese1(uint8_t x, uint8_t y, uint8_t idx)
{
    uint8_t t;

    OledSetPosition(x, y);
    for (t = 0; t < 16; t++)
    {
        WriteData(fonts1[idx][t]);
    }

    OledSetPosition(x, y + 1);
    for (t = 16; t < 32; t++)
    {
        WriteData(fonts1[idx][t]);
    }
}

/**
 * @brief Display Chinese characters on the OLED screen.
 *
 * This function displays Chinese characters from fonts2 on the OLED screen at the specified position.
 *
 * @param x The x-coordinate of the position.
 * @param y The y-coordinate of the position.
 * @param idx The index of the character in fonts2.
 */
void OledShowChinese2(uint8_t x, uint8_t y, uint8_t idx)
{
    uint8_t t;

    OledSetPosition(x, y);
    for (t = 0; t < 16; t++)
    {
        WriteData(fonts2[32 * idx + t]);
    }

    OledSetPosition(x, y + 1);
    for (t = 16; t < 32; t++)
    {
        WriteData(fonts2[32 * idx + t]);
    }
}

/**
 * @brief Display latitude and longitude on the OLED screen.
 *
 * This function displays latitude and longitude information on the OLED screen.
 *
 * @param arg Unused parameter.
 */
void Oled_function_jingwei(void *arg)
{
    (void)arg;
    OledFillScreen(0x00);

    OledShowChinese2(0, 0, 6);
    OledShowChinese2(18, 0, 7);

    OledShowChinese2(0, 2, 8);
    OledShowChinese2(18, 2, 7);
}

/**
 * @brief Clear the OLED screen.
 *
 * This function clears the OLED screen.
 *
 * @param arg Unused parameter.
 */
void Oled_function_number(void *arg)
{
    (void)arg;

    OledFillScreen(0x00);
}

/**
 * @brief Initialize the OLED screen.
 *
 * This function initializes the OLED screen.
 */
void Oled_init()
{
    OledInit();
}
